package com.xnccc.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.owen.mapx.MapX;
import com.xnccc.audioset.MainActivity;
import com.xnccc.audioset.R;
import com.xnccc.view.XNCCCDialog;
import com.xnccc.view.XNCCCDialog.XNCCCDialogListItemListener;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import util.DP;

public class DpFragment extends Fragment implements OnClickListener {

	private MapX bird;
	private ArrayList<Map<String, String>> time_data1, time_data2, time_data3;
	private TextView num2, num3, num4, num6, num7;
	private String nowTxt = "0HZ";

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		bird = MainActivity.bird;
		View mView = inflater.inflate(R.layout.fragment_dp, container, false);
		initView(mView);
		return mView;
	}

	private void initView(View mView) {
		
		mView.findViewById(R.id.rl_2).setOnClickListener(this);
		mView.findViewById(R.id.rl_3).setOnClickListener(this);
		mView.findViewById(R.id.rl_4).setOnClickListener(this);
		mView.findViewById(R.id.rl_6).setOnClickListener(this);
		mView.findViewById(R.id.rl_7).setOnClickListener(this);

		num2 = (TextView) mView.findViewById(R.id.dp_num2);
		num3 = (TextView) mView.findViewById(R.id.dp_num3);
		num4 = (TextView) mView.findViewById(R.id.dp_num4);
		num6 = (TextView) mView.findViewById(R.id.dp_num6);
		num7 = (TextView) mView.findViewById(R.id.dp_num7);
		
		num2.setText(bird.getFreq(MapX.CH_R, 1)+"");
		num3.setText(bird.getFreq(MapX.CH_C, 1)+"");
		num4.setText(bird.getFreq(MapX.CH_SR, 1)+"");
		num6.setText(bird.getFreq(MapX.CH_LFE, 1)+"");
		num7.setText(bird.getFreq(MapX.CH_LFE, 8)+"");

		init();
	}

	private void init() {
		
		
		time_data1 = new ArrayList<Map<String, String>>();
		for (int i = 60; i < 151; i++) {
			Map<String, String> map_pb = new HashMap<String, String>();
			map_pb.put("id", i + "");
			map_pb.put("text", i + "");
			time_data1.add(map_pb);
		}

		time_data2 = new ArrayList<Map<String, String>>();
		for (int i = 30; i < 51; i++) {
			Map<String, String> map_pb = new HashMap<String, String>();
			map_pb.put("id", i + "");
			map_pb.put("text", i + "");
			time_data2.add(map_pb);
		}

		time_data3 = new ArrayList<Map<String, String>>();
		for (int i = 80; i < 121; i++) {
			Map<String, String> map_pb = new HashMap<String, String>();
			map_pb.put("id", i + "");
			map_pb.put("text", i + "");
			time_data3.add(map_pb);
		}
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.rl_2:
			XNCCCDialog.showListDialog(getActivity(), time_data1, 0, new XNCCCDialogListItemListener() {

				@Override
				public void OnChoseListener(Dialog dialog, Map<String, String> item) {
					nowTxt = item.get("text");
					num2.setText(nowTxt);
					bird.setFreq(MapX.CH_R, 1, Integer.parseInt(num2.getText().toString()));
				}
			});
			break;
		case R.id.rl_3:
			XNCCCDialog.showListDialog(getActivity(), time_data1, 0, new XNCCCDialogListItemListener() {

				@Override
				public void OnChoseListener(Dialog dialog, Map<String, String> item) {
					nowTxt = item.get("text");
					num3.setText(nowTxt);
					bird.setFreq(MapX.CH_C, 1, Integer.parseInt(num3.getText().toString()));
					DP.center = nowTxt;
				}
			});
			break;
		case R.id.rl_4:
			XNCCCDialog.showListDialog(getActivity(), time_data1, 0, new XNCCCDialogListItemListener() {

				@Override
				public void OnChoseListener(Dialog dialog, Map<String, String> item) {
					nowTxt = item.get("text");
					num4.setText(nowTxt);
					bird.setFreq(MapX.CH_SL, 1, Integer.parseInt(num4.getText().toString()));
				}
			});
			break;
		case R.id.rl_6:
			XNCCCDialog.showListDialog(getActivity(), time_data2, 0, new XNCCCDialogListItemListener() {

				@Override
				public void OnChoseListener(Dialog dialog, Map<String, String> item) {
					nowTxt = item.get("text");
					num6.setText(nowTxt);
					bird.setFreq(MapX.CH_LFE, 1, Integer.parseInt(num6.getText().toString()));
					DP.LFE_UP = nowTxt;
				}
			});
			break;
		case R.id.rl_7:
			XNCCCDialog.showListDialog(getActivity(), time_data3, 0, new XNCCCDialogListItemListener() {

				@Override
				public void OnChoseListener(Dialog dialog, Map<String, String> item) {
					nowTxt = item.get("text");
					num7.setText(nowTxt);
					bird.setFreq(MapX.CH_LFE, 8, Integer.parseInt(num7.getText().toString()));
					DP.LFE_DOWN = nowTxt;
				}
			});
			break;
		}
	}
}
